import { getChannelsAPI } from "api/channel";
import { Select } from "antd";
import { useEffect, useState } from "react";
const { Option } = Select;
export default function Channel(props) {
  // 声明状态
  const [channelList, setChannelList] = useState([]);
  // 请求频道列表数据
  const getChannelsFn = async () => {
    const res = await getChannelsAPI();
    // console.log("频道列表", res);
    setChannelList(res.data.channels);
  };
  //   挂载时
  useEffect(() => {
    getChannelsFn();
  }, []);
  return (
    <>
      <Select {...props}>
        {channelList.map((item) => {
          return (
            <Option key={item.id} value={item.id}>
              {item.name}
            </Option>
          );
        })}
      </Select>
    </>
  );
}
